/*
 * Copyright 2014 RSA 2014 group Alpha @ CS, Aarhus University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 

package cs.rsa.ts14.alpha;

import cs.rsa.ts14.framework.LineSequenceState;

/** 
 * Roles:
 *   This class plays the Context role of the Strategy pattern
 *   with respect to the EmptyLineStrategy.
 *   
 * @author RSA 2014 group Alpha @ CS, Aarhus University
 */

public class StandardEmptyLineStrategy implements EmptyLineStrategy {

	private int emptyCount;

	public StandardEmptyLineStrategy() {
		resetCounter();
	}
	
    private void resetCounter() {
		emptyCount = 0;
    }
    
	
	@Override
	public LineSequenceState handleEmptyLine(LineSequenceState currentState) {
		LineSequenceState newState = null;
	    emptyCount++;
	    if(emptyCount < 3)
	      newState = currentState;
	    else
	      newState = new IllegalState("Illegal to have three consecutive empty lines.");
		return newState;
	}

	@Override
	public void otherLineTypeReceived() {
		resetCounter();
	}
}
